package com.ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.service.StudentServiceImpl;

@Controller
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentServiceImpl studentService;
    
    @RequestMapping("/categoryShow")
    public String categoryShow(){        
        return "student_category :: content";
    }
    
    @RequestMapping("/courseShow")
    public String courseShow(){        
        return "student_course :: content";
    }
    
    @RequestMapping("/categoryList")
    @ResponseBody
    public String categoryList(){
        return studentService.findAllCategories();
    }
    
    @RequestMapping("/courseList")
    @ResponseBody
    public String courseList(){
        return studentService.findAllCourses();
    }
    
    @GetMapping("/category/{cid}")
    @ResponseBody
    public String getCategory(@PathVariable int cid){
        return studentService.getCategory(cid);
    }
    
    @GetMapping("/course/{courseId}")
    @ResponseBody
    public String getCourse(@PathVariable int courseId){
        return studentService.getCourse(courseId);
    }
    
    @GetMapping("/coursesByCategory/{cid}")
    @ResponseBody
    public String getCoursesByCategory(@PathVariable int cid){
        return studentService.findCoursesByCategory(cid);
    }
    
    @RequestMapping("/addCategory")
    @ResponseBody
    public String addCategory(String cname, String description){
        return studentService.addCategory(cname, description);
    }
    
    @RequestMapping("/updateCategory")
    @ResponseBody
    public String updateCategory(int cid, String cname, String description){
        return studentService.updateCategory(cid, cname, description);
    }
    
    @RequestMapping("/deleteCategory")
    @ResponseBody
    public String deleteCategory(int cid){
        return studentService.deleteCategory(cid);
    }
    
    @RequestMapping("/addCourse")
    @ResponseBody
    public String addCourse(String course_name, double credit, String teacher_name, String description, int cid){
        return studentService.addCourse(course_name, credit, teacher_name, description, cid);
    }
    
    @RequestMapping("/updateCourse")
    @ResponseBody
    public String updateCourse(int course_id, String course_name, double credit, String teacher_name, String description, int cid){
        return studentService.updateCourse(course_id, course_name, credit, teacher_name, description, cid);
    }
    
    @RequestMapping("/deleteCourse")
    @ResponseBody
    public String deleteCourse(int course_id){
        return studentService.deleteCourse(course_id);
    }
} 